package com.cpos.base.mongo.controller;

import com.cpos.base.mongo.entity.Order;
import com.cpos.base.mongo.service.OrderService;
import com.cpos.bkge.base.ResultInfo;
import com.cpos.bkge.entity.CposBkUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @创建人 Leiwenlong
 * @创建时间 2020/9/29
 * @描述
 **/
@RestController
@Slf4j
@RequestMapping("/mongo/order")
public class OrderContrller {

    @Autowired
    private OrderService orderService;

    /*
     *   插入方法
     * */
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public ResultInfo insert(@RequestBody Order order) {
        ResultInfo resultInfo = new ResultInfo();
        try {
            orderService.insertOrderBy(order);
            resultInfo.setMsg("插入成功");
        } catch (Exception e) {
            resultInfo.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return resultInfo;
    }

    /*
     *   插入方法
     * */
    @RequestMapping(value = "/find", method = RequestMethod.POST)
    public ResultInfo find(@RequestBody Order order) {
        ResultInfo resultInfo = new ResultInfo();
        try {
            List<Order> orderBy = orderService.findOrderBy(order);
            resultInfo.setData(orderBy);
            resultInfo.setMsg("查询成功");
        } catch (Exception e) {
            resultInfo.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return resultInfo;
    }

}
